/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cube;

import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.*;

/**
 *
 * @author antonio
 */
public class CubeFactory {

    private String uriCube;
    private String uriGraph;

    public CubeFactory(String uriCube, String uriGraph)
    {
        this.uriCube = uriCube;
        this.uriGraph = uriGraph;
    }

    public Cube createCube()
    {
        Cube cubix = new Cube();
        cubix.setUri(uriCube);

        String testoQuery = "select ?nome ?sub from <" + this.uriGraph + "> where" +
                    " {<"+ this.uriCube +"> <http://unime.it/cubixprop#Nome> ?nome." +
                    "<" +  this.uriCube + "> <http://unime.it/cubixprop#subLevelCubeOf> ?sub}";

        Query cubixQuery = QueryFactory.create(testoQuery);

        QueryExecution qexec = null;

        try{

            qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", cubixQuery);

            ResultSet results = qexec.execSelect();

            QuerySolution soln = results.nextSolution();
            String nome = soln.get("nome").toString();
            String subUri = soln.get("sub").toString();

            cubix.setNome(nome);
            cubix.setUriSub(subUri);


        }finally{
            qexec.close();
        }


       // Literal  uri = soln.getLiteral("persone");

       // System.out.print("CreateCube: " + uri.toString() + "\t\n\n");

       // cubix.setUri(abs.getString());

        return cubix;
    }


}
